﻿/**
 * Sample React Native App
 * https://github.com/Facebook/react-native
*/ 
'use strict';
import React,{Component,View} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  Alert,
  TouchableHighlight,
  NativeModules
} from 'react-native';
var PostAndroid = NativeModules.PostAndroid;
var UpdateDialog = NativeModules.UpdateDialog;
var APKurl;
var MD5;

async function measureLayout() {
  try {
    var {
      length
    } = 

    console.log(relativeX + ':' + relativeY + ':' + width + ':' + height);
  } catch (e) {
    console.error(e);
  }
}

class CustomButton extends Component {
  render() {
    return (
      <TouchableHighlight
        style={styles.button}
        underlayColor="#a5a5a5"
        onPress={this.props.onPress}>
        <Text style={styles.buttonText}>{this.props.text}</Text>
      </TouchableHighlight>
    );
  }
}
class CheckModule extends Component{
	async  doUpdate(){
			try {
              var currentSize = await PostAndroid.startUpdate(APKurl,MD5);
			  PostAndroid.incrementProgress(currentSize);
			}
	        catch(e){
		    console.error(e);
	        }
        }
	render(){
		return(
		
		<CustomButton
		 text = '检查更新'
		 onPress={()=> PostAndroid.checkVersion(
               'http://120.27.116.146/update.xml',
			   (description,url,md5)=>{
				   APKurl = url;
				   MD5 = md5;
				  Alert.alert('版本描述：',description,
				   [{text:'取消',onPress:()=>console.log("点击取消了")},
				    {text:'更新',onPress:()=>this.doUpdate()}
				   ])
			   },
			  (msg)=>{
				  Alert.alert('检查更新','没有新版本',
				  [{text:'下个版本自动更新',onPress:()=>UPdateDialog.alert('你决定下个版本自动更新了！')},
					{text:'确定',onPress:()=>console.log('点击确定了')}
				  ])
			  }
			  )}
		 />
		);
	}
		
}

const styles = StyleSheet.create({
  button: {
    margin:5,
    backgroundColor: 'white',
    padding: 15,
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderBottomColor: '#cdcdcd',
  }
});
module.export = CheckModule;
AppRegistry.registerComponent('AwesomeProject', () => CheckModule);
